using UnityEngine;

public class ResultUI_level_lose : MonoBehaviour
{
	private GameObject resultobj;

	public UIEventListener mainbtn;

	public UIEventListener retrybtn;

	public UIEventListener strongbtn;

	public UILabel explabel;

	public UILabel moneylabel;

	public UILabel energylabel;

	private GameLevel curgamelevel_info;

	public UISlider expslider;

	public UISprite currankflag;

	public UISprite nextrankflag;

	public UILabel exp_label;

	private float curexp;

	private float rateexp;

	private int endexp;

	private bool exprunflag;

	public UIPanel guidepanel;

	public Transform fingerflag;

	public Transform parentwi;

	public UIWidget colliderwi;

	private bool isshowguide;

	private bool poprankui;

	private int firstlevel;

	private bool temp_first;

	private void Start()
	{
		mainbtn.onClick = OnClickMainBtn;
		retrybtn.onClick = OnClickretryBtn;
		strongbtn.onClick = OnClickstrongBtn;
	}

	public void showguideUI()
	{
		guidepanel.alpha = 1f; guidepanel.gameObject.SetActive(true);
		strongbtn.transform.parent = parentwi;
		fingerflag.transform.parent = strongbtn.transform;
		fingerflag.transform.localPosition = new Vector3(24f, -32f, 0f);
	}

	public void initinfo()
	{
		curgamelevel_info = TasksController.instance.curgamelevel;
		int tasknum = TasksController.instance.GetTasknum();
		float num = 0.8f;
		switch (tasknum)
		{
			case 1:
				num = 0.3f;
				break;
			case 2:
				num = 0.6f;
				break;
			case 3:
				num = 0.8f;
				break;
		}
		explabel.text = string.Empty + (int)((float)curgamelevel_info.success_exp * num);
		moneylabel.text = string.Empty + (int)((float)curgamelevel_info.success_gold * num);
		curexp = GamePlayerprefs.instance.allexp;
		endexp = (int)curexp + (int)((float)curgamelevel_info.success_exp * num);
		rateexp = (float)(int)((float)curgamelevel_info.success_exp * num) / 2f;
		expshow((int)curexp);
		exprunflag = true;
		energylabel.text = string.Empty + curgamelevel_info.energy;
		GamePlayerprefs.instance.add_exp((int)((float)curgamelevel_info.success_exp * num));
		GamePlayerprefs.instance.add_money((int)((float)curgamelevel_info.success_gold * num));
		saveAchi();
	}

	public void saveAchi()
	{
		GamePlayerprefs.instance.readachievement();
		GamePlayerprefs.instance.readdailytask();
		GamePlayerprefs.instance.savefightinfo();
	}

	private void Update()
	{
		if (exprunflag)
		{
			if (curexp < (float)endexp)
			{
				curexp += Time.deltaTime * rateexp;
			}
			else
			{
				curexp = endexp;
				exprunflag = false;
			}
			expshow((int)curexp);
		}
	}

	public void enable(bool showguide)
	{
		isshowguide = showguide;
		if (resultobj == null)
		{
			resultobj = base.gameObject;
		}
		NGUITools.SetActive(resultobj, state: true);
		initinfo();
		MonoInstance<AudioController>.instance.play(AudioType.UI_gameover_fail, 0f);
		if (showguide)
		{
			colliderwi.alpha = 0f; colliderwi.gameObject.SetActive(false);
			showguideUI();
			GamePlayerprefs.instance.set_popsaleflag();
		}
		else
		{
			colliderwi.alpha = 1f; colliderwi.gameObject.SetActive(true);
			Invoke("showAD", 0.5f);
		}
	}

	public void showAD()
	{
		colliderwi.alpha = 0f; colliderwi.gameObject.SetActive(false);
		Platform.ShowFeatureView();
		Platform.ShowFullScreenSmall();
	}

	public void expshow(int expnum)
	{
		expdata exp = GamePlayerprefs.instance.GetExp(expnum);
		if (exp.level >= 19)
		{
			expslider.value = 1f;
			exp_label.text = string.Empty;
			currankflag.spriteName = "19." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.enabled = false;
			currankflag.SetDimensions(56, 48);
			nextrankflag.SetDimensions(56, 48);
		}
		else
		{
			expslider.value = (float)exp.curexp / (float)exp.maxexp;
			exp_label.text = string.Empty + exp.curexp + "/" + exp.maxexp;
			currankflag.spriteName = string.Empty + exp.level + "." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.spriteName = string.Empty + (exp.level + 1) + "." + GamePlayerprefs.instance.ranknameImage[exp.level];
			if (exp.level >= 15)
			{
				currankflag.SetDimensions(56, 48);
				nextrankflag.SetDimensions(56, 48);
			}
			else if (exp.level < 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(40, 44);
			}
			if (exp.level == 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(56, 48);
			}
		}
		showrankeui(exp.level);
	}

	public void showrankeui(int level)
	{
		if (!poprankui && !isshowguide)
		{
			if (!temp_first)
			{
				firstlevel = level;
				temp_first = true;
			}
			if (level == firstlevel + 1)
			{
				GameUIController.instance.enable_rankui();
				poprankui = true;
			}
		}
	}

	public void OnClickMainBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		MenuUIController.beginshow = BeginShow.main;
		Time.timeScale = 1f;
		UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
		MidLoading.loadlevel = 0;
	}

	public void OnClickretryBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		if (GamePlayerprefs.instance.DecEnergy(curgamelevel_info.energy))
		{
			Platform.flurryEvent_level(GlobalInf.CurrentLevel, 9);
			UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
			MidLoading.loadlevel = 2;
			GlobalInf.gameover = false;
		}
		else
		{
			MenuUIController.beginshow = BeginShow.level_energy;
			Time.timeScale = 1f;
			UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
			MidLoading.loadlevel = 0;
		}
	}

	public void OnClickstrongBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		MenuUIController.beginshow = BeginShow.garage;
		Time.timeScale = 1f;
		UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
		MidLoading.loadlevel = 0;
	}

	public void disable()
	{
		NGUITools.SetActive(resultobj, state: false);
	}
}
